

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Exception Handling in LLVM &mdash; LLVM 3.2 documentation</title>
    
    <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '3.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="LLVM 3.2 documentation" href="index.html" />
    <link rel="up" title="Subsystem Documentation" href="subsystems.html" />
    <link rel="next" title="LLVM Link Time Optimization: Design and Implementation" href="LinkTimeOptimization.html" />
    <link rel="prev" title="The LLVM Target-Independent Code Generator" href="CodeGenerator.html" />
<style type="text/css">
  table.right { float: right; margin-left: 20px; }
  table.right td { border: 1px solid #ccc; }
</style>

  </head>
  <body>
<div class="logo">
  <a href="index.html">
    <img src="_static/logo.png"
         alt="LLVM Logo" width="250" height="88"/></a>
</div>

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="LinkTimeOptimization.html" title="LLVM Link Time Optimization: Design and Implementation"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="CodeGenerator.html" title="The LLVM Target-Independent Code Generator"
             accesskey="P">previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>

          <li><a href="subsystems.html" accesskey="U">Subsystem Documentation</a> &raquo;</li> 
      </ul>
    </div>

      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Exception Handling in LLVM</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a><ul>
<li><a class="reference internal" href="#itanium-abi-zero-cost-exception-handling">Itanium ABI Zero-cost Exception Handling</a></li>
<li><a class="reference internal" href="#setjmp-longjmp-exception-handling">Setjmp/Longjmp Exception Handling</a></li>
<li><a class="reference internal" href="#overview">Overview</a></li>
</ul>
</li>
<li><a class="reference internal" href="#llvm-code-generation">LLVM Code Generation</a><ul>
<li><a class="reference internal" href="#throw">Throw</a></li>
<li><a class="reference internal" href="#try-catch">Try/Catch</a></li>
<li><a class="reference internal" href="#cleanups">Cleanups</a></li>
<li><a class="reference internal" href="#throw-filters">Throw Filters</a></li>
<li><a class="reference internal" href="#restrictions">Restrictions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#exception-handling-intrinsics">Exception Handling Intrinsics</a><ul>
<li><a class="reference internal" href="#llvm-eh-typeid-for">llvm.eh.typeid.for</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-setjmp">llvm.eh.sjlj.setjmp</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-longjmp">llvm.eh.sjlj.longjmp</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-lsda">llvm.eh.sjlj.lsda</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-callsite">llvm.eh.sjlj.callsite</a></li>
</ul>
</li>
<li><a class="reference internal" href="#asm-table-formats">Asm Table Formats</a><ul>
<li><a class="reference internal" href="#exception-handling-frame">Exception Handling Frame</a></li>
<li><a class="reference internal" href="#exception-tables">Exception Tables</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="CodeGenerator.html"
                        title="previous chapter">The LLVM Target-Independent Code Generator</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="LinkTimeOptimization.html"
                        title="next chapter">LLVM Link Time Optimization: Design and Implementation</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/ExceptionHandling.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="exception-handling-in-llvm">
<span id="exception-handling"></span><h1>Exception Handling in LLVM<a class="headerlink" href="#exception-handling-in-llvm" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id7">Introduction</a><ul>
<li><a class="reference internal" href="#itanium-abi-zero-cost-exception-handling" id="id8">Itanium ABI Zero-cost Exception Handling</a></li>
<li><a class="reference internal" href="#setjmp-longjmp-exception-handling" id="id9">Setjmp/Longjmp Exception Handling</a></li>
<li><a class="reference internal" href="#overview" id="id10">Overview</a></li>
</ul>
</li>
<li><a class="reference internal" href="#llvm-code-generation" id="id11">LLVM Code Generation</a><ul>
<li><a class="reference internal" href="#throw" id="id12">Throw</a></li>
<li><a class="reference internal" href="#try-catch" id="id13">Try/Catch</a></li>
<li><a class="reference internal" href="#cleanups" id="id14">Cleanups</a></li>
<li><a class="reference internal" href="#throw-filters" id="id15">Throw Filters</a></li>
<li><a class="reference internal" href="#restrictions" id="id16">Restrictions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#exception-handling-intrinsics" id="id17">Exception Handling Intrinsics</a><ul>
<li><a class="reference internal" href="#llvm-eh-typeid-for" id="id18">llvm.eh.typeid.for</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-setjmp" id="id19">llvm.eh.sjlj.setjmp</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-longjmp" id="id20">llvm.eh.sjlj.longjmp</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-lsda" id="id21">llvm.eh.sjlj.lsda</a></li>
<li><a class="reference internal" href="#llvm-eh-sjlj-callsite" id="id22">llvm.eh.sjlj.callsite</a></li>
</ul>
</li>
<li><a class="reference internal" href="#asm-table-formats" id="id23">Asm Table Formats</a><ul>
<li><a class="reference internal" href="#exception-handling-frame" id="id24">Exception Handling Frame</a></li>
<li><a class="reference internal" href="#exception-tables" id="id25">Exception Tables</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id7">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>This document is the central repository for all information pertaining to
exception handling in LLVM.  It describes the format that LLVM exception
handling information takes, which is useful for those interested in creating
front-ends or dealing directly with the information.  Further, this document
provides specific examples of what exception handling information is used for in
C and C++.</p>
<div class="section" id="itanium-abi-zero-cost-exception-handling">
<h3><a class="toc-backref" href="#id8">Itanium ABI Zero-cost Exception Handling</a><a class="headerlink" href="#itanium-abi-zero-cost-exception-handling" title="Permalink to this headline">¶</a></h3>
<p>Exception handling for most programming languages is designed to recover from
conditions that rarely occur during general use of an application.  To that end,
exception handling should not interfere with the main flow of an application&#8217;s
algorithm by performing checkpointing tasks, such as saving the current pc or
register state.</p>
<p>The Itanium ABI Exception Handling Specification defines a methodology for
providing outlying data in the form of exception tables without inlining
speculative exception handling code in the flow of an application&#8217;s main
algorithm.  Thus, the specification is said to add &#8220;zero-cost&#8221; to the normal
execution of an application.</p>
<p>A more complete description of the Itanium ABI exception handling runtime
support of can be found at <a class="reference external" href="http://www.codesourcery.com/cxx-abi/abi-eh.html">Itanium C++ ABI: Exception Handling</a>. A description of the
exception frame format can be found at <a class="reference external" href="http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html">Exception Frames</a>,
with details of the DWARF 4 specification at <a class="reference external" href="http://dwarfstd.org/Dwarf4Std.php">DWARF 4 Standard</a>.  A description for the C++ exception
table formats can be found at <a class="reference external" href="http://www.codesourcery.com/cxx-abi/exceptions.pdf">Exception Handling Tables</a>.</p>
</div>
<div class="section" id="setjmp-longjmp-exception-handling">
<h3><a class="toc-backref" href="#id9">Setjmp/Longjmp Exception Handling</a><a class="headerlink" href="#setjmp-longjmp-exception-handling" title="Permalink to this headline">¶</a></h3>
<p>Setjmp/Longjmp (SJLJ) based exception handling uses LLVM intrinsics
<a class="reference internal" href="#llvm-eh-sjlj-setjmp">llvm.eh.sjlj.setjmp</a> and <a class="reference internal" href="#llvm-eh-sjlj-longjmp">llvm.eh.sjlj.longjmp</a> to handle control flow for
exception handling.</p>
<p>For each function which does exception processing &#8212; be it <tt class="docutils literal"><span class="pre">try</span></tt>/<tt class="docutils literal"><span class="pre">catch</span></tt>
blocks or cleanups &#8212; that function registers itself on a global frame
list. When exceptions are unwinding, the runtime uses this list to identify
which functions need processing.</p>
<p>Landing pad selection is encoded in the call site entry of the function
context. The runtime returns to the function via <a class="reference internal" href="#llvm-eh-sjlj-longjmp">llvm.eh.sjlj.longjmp</a>, where
a switch table transfers control to the appropriate landing pad based on the
index stored in the function context.</p>
<p>In contrast to DWARF exception handling, which encodes exception regions and
frame information in out-of-line tables, SJLJ exception handling builds and
removes the unwind frame context at runtime. This results in faster exception
handling at the expense of slower execution when no exceptions are thrown. As
exceptions are, by their nature, intended for uncommon code paths, DWARF
exception handling is generally preferred to SJLJ.</p>
</div>
<div class="section" id="overview">
<h3><a class="toc-backref" href="#id10">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h3>
<p>When an exception is thrown in LLVM code, the runtime does its best to find a
handler suited to processing the circumstance.</p>
<p>The runtime first attempts to find an <em>exception frame</em> corresponding to the
function where the exception was thrown.  If the programming language supports
exception handling (e.g. C++), the exception frame contains a reference to an
exception table describing how to process the exception.  If the language does
not support exception handling (e.g. C), or if the exception needs to be
forwarded to a prior activation, the exception frame contains information about
how to unwind the current activation and restore the state of the prior
activation.  This process is repeated until the exception is handled. If the
exception is not handled and no activations remain, then the application is
terminated with an appropriate error message.</p>
<p>Because different programming languages have different behaviors when handling
exceptions, the exception handling ABI provides a mechanism for
supplying <em>personalities</em>. An exception handling personality is defined by
way of a <em>personality function</em> (e.g. <tt class="docutils literal"><span class="pre">__gxx_personality_v0</span></tt> in C++),
which receives the context of the exception, an <em>exception structure</em>
containing the exception object type and value, and a reference to the exception
table for the current function.  The personality function for the current
compile unit is specified in a <em>common exception frame</em>.</p>
<p>The organization of an exception table is language dependent. For C++, an
exception table is organized as a series of code ranges defining what to do if
an exception occurs in that range. Typically, the information associated with a
range defines which types of exception objects (using C++ <em>type info</em>) that are
handled in that range, and an associated action that should take place. Actions
typically pass control to a <em>landing pad</em>.</p>
<p>A landing pad corresponds roughly to the code found in the <tt class="docutils literal"><span class="pre">catch</span></tt> portion of
a <tt class="docutils literal"><span class="pre">try</span></tt>/<tt class="docutils literal"><span class="pre">catch</span></tt> sequence. When execution resumes at a landing pad, it
receives an <em>exception structure</em> and a <em>selector value</em> corresponding to the
<em>type</em> of exception thrown. The selector is then used to determine which <em>catch</em>
should actually process the exception.</p>
</div>
</div>
<div class="section" id="llvm-code-generation">
<h2><a class="toc-backref" href="#id11">LLVM Code Generation</a><a class="headerlink" href="#llvm-code-generation" title="Permalink to this headline">¶</a></h2>
<p>From a C++ developer&#8217;s perspective, exceptions are defined in terms of the
<tt class="docutils literal"><span class="pre">throw</span></tt> and <tt class="docutils literal"><span class="pre">try</span></tt>/<tt class="docutils literal"><span class="pre">catch</span></tt> statements. In this section we will describe the
implementation of LLVM exception handling in terms of C++ examples.</p>
<div class="section" id="throw">
<h3><a class="toc-backref" href="#id12">Throw</a><a class="headerlink" href="#throw" title="Permalink to this headline">¶</a></h3>
<p>Languages that support exception handling typically provide a <tt class="docutils literal"><span class="pre">throw</span></tt>
operation to initiate the exception process. Internally, a <tt class="docutils literal"><span class="pre">throw</span></tt> operation
breaks down into two steps.</p>
<ol class="arabic simple">
<li>A request is made to allocate exception space for an exception structure.
This structure needs to survive beyond the current activation. This structure
will contain the type and value of the object being thrown.</li>
<li>A call is made to the runtime to raise the exception, passing the exception
structure as an argument.</li>
</ol>
<p>In C++, the allocation of the exception structure is done by the
<tt class="docutils literal"><span class="pre">__cxa_allocate_exception</span></tt> runtime function. The exception raising is handled
by <tt class="docutils literal"><span class="pre">__cxa_throw</span></tt>. The type of the exception is represented using a C++ RTTI
structure.</p>
</div>
<div class="section" id="try-catch">
<h3><a class="toc-backref" href="#id13">Try/Catch</a><a class="headerlink" href="#try-catch" title="Permalink to this headline">¶</a></h3>
<p>A call within the scope of a <em>try</em> statement can potentially raise an
exception. In those circumstances, the LLVM C++ front-end replaces the call with
an <tt class="docutils literal"><span class="pre">invoke</span></tt> instruction. Unlike a call, the <tt class="docutils literal"><span class="pre">invoke</span></tt> has two potential
continuation points:</p>
<ol class="arabic simple">
<li>where to continue when the call succeeds as per normal, and</li>
<li>where to continue if the call raises an exception, either by a throw or the
unwinding of a throw</li>
</ol>
<p>The term used to define a the place where an <tt class="docutils literal"><span class="pre">invoke</span></tt> continues after an
exception is called a <em>landing pad</em>. LLVM landing pads are conceptually
alternative function entry points where an exception structure reference and a
type info index are passed in as arguments. The landing pad saves the exception
structure reference and then proceeds to select the catch block that corresponds
to the type info of the exception object.</p>
<p>The LLVM <a class="reference external" href="LangRef.html#i_landingpad">landingpad instruction</a> is used to convey
information about the landing pad to the back end. For C++, the <tt class="docutils literal"><span class="pre">landingpad</span></tt>
instruction returns a pointer and integer pair corresponding to the pointer to
the <em>exception structure</em> and the <em>selector value</em> respectively.</p>
<p>The <tt class="docutils literal"><span class="pre">landingpad</span></tt> instruction takes a reference to the personality function to
be used for this <tt class="docutils literal"><span class="pre">try</span></tt>/<tt class="docutils literal"><span class="pre">catch</span></tt> sequence. The remainder of the instruction is
a list of <em>cleanup</em>, <em>catch</em>, and <em>filter</em> clauses. The exception is tested
against the clauses sequentially from first to last. The selector value is a
positive number if the exception matched a type info, a negative number if it
matched a filter, and zero if it matched a cleanup. If nothing is matched, the
behavior of the program is <a class="reference internal" href="#undefined">undefined</a>. If a type info matched, then the
selector value is the index of the type info in the exception table, which can
be obtained using the <a class="reference internal" href="#llvm-eh-typeid-for">llvm.eh.typeid.for</a> intrinsic.</p>
<p>Once the landing pad has the type info selector, the code branches to the code
for the first catch. The catch then checks the value of the type info selector
against the index of type info for that catch.  Since the type info index is not
known until all the type infos have been gathered in the backend, the catch code
must call the <a class="reference internal" href="#llvm-eh-typeid-for">llvm.eh.typeid.for</a> intrinsic to determine the index for a given
type info. If the catch fails to match the selector then control is passed on to
the next catch.</p>
<p>Finally, the entry and exit of catch code is bracketed with calls to
<tt class="docutils literal"><span class="pre">__cxa_begin_catch</span></tt> and <tt class="docutils literal"><span class="pre">__cxa_end_catch</span></tt>.</p>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">__cxa_begin_catch</span></tt> takes an exception structure reference as an argument
and returns the value of the exception object.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">__cxa_end_catch</span></tt> takes no arguments. This function:</p>
<ol class="arabic simple">
<li>Locates the most recently caught exception and decrements its handler
count,</li>
<li>Removes the exception from the <em>caught</em> stack if the handler count goes to
zero, and</li>
<li>Destroys the exception if the handler count goes to zero and the exception
was not re-thrown by throw.</li>
</ol>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">a rethrow from within the catch may replace this call with a
<tt class="docutils literal"><span class="pre">__cxa_rethrow</span></tt>.</p>
</div>
</li>
</ul>
</div>
<div class="section" id="cleanups">
<h3><a class="toc-backref" href="#id14">Cleanups</a><a class="headerlink" href="#cleanups" title="Permalink to this headline">¶</a></h3>
<p>A cleanup is extra code which needs to be run as part of unwinding a scope.  C++
destructors are a typical example, but other languages and language extensions
provide a variety of different kinds of cleanups. In general, a landing pad may
need to run arbitrary amounts of cleanup code before actually entering a catch
block. To indicate the presence of cleanups, a <a class="reference external" href="LangRef.html#i_landingpad">landingpad
instruction</a> should have a <em>cleanup</em>
clause. Otherwise, the unwinder will not stop at the landing pad if there are no
catches or filters that require it to.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Do not allow a new exception to propagate out of the execution of a
cleanup. This can corrupt the internal state of the unwinder.  Different
languages describe different high-level semantics for these situations: for
example, C++ requires that the process be terminated, whereas Ada cancels both
exceptions and throws a third.</p>
</div>
<p>When all cleanups are finished, if the exception is not handled by the current
function, resume unwinding by calling the <a class="reference external" href="LangRef.html#i_resume">resume
instruction</a>, passing in the result of the
<tt class="docutils literal"><span class="pre">landingpad</span></tt> instruction for the original landing pad.</p>
</div>
<div class="section" id="throw-filters">
<h3><a class="toc-backref" href="#id15">Throw Filters</a><a class="headerlink" href="#throw-filters" title="Permalink to this headline">¶</a></h3>
<p>C++ allows the specification of which exception types may be thrown from a
function. To represent this, a top level landing pad may exist to filter out
invalid types. To express this in LLVM code the <a class="reference external" href="LangRef.html#i_landingpad">landingpad
instruction</a> will have a filter clause. The clause
consists of an array of type infos.  <tt class="docutils literal"><span class="pre">landingpad</span></tt> will return a negative value
if the exception does not match any of the type infos. If no match is found then
a call to <tt class="docutils literal"><span class="pre">__cxa_call_unexpected</span></tt> should be made, otherwise
<tt class="docutils literal"><span class="pre">_Unwind_Resume</span></tt>.  Each of these functions requires a reference to the
exception structure.  Note that the most general form of a <tt class="docutils literal"><span class="pre">landingpad</span></tt>
instruction can have any number of catch, cleanup, and filter clauses (though
having more than one cleanup is pointless). The LLVM C++ front-end can generate
such <tt class="docutils literal"><span class="pre">landingpad</span></tt> instructions due to inlining creating nested exception
handling scopes.</p>
</div>
<div class="section" id="restrictions">
<span id="undefined"></span><h3><a class="toc-backref" href="#id16">Restrictions</a><a class="headerlink" href="#restrictions" title="Permalink to this headline">¶</a></h3>
<p>The unwinder delegates the decision of whether to stop in a call frame to that
call frame&#8217;s language-specific personality function. Not all unwinders guarantee
that they will stop to perform cleanups. For example, the GNU C++ unwinder
doesn&#8217;t do so unless the exception is actually caught somewhere further up the
stack.</p>
<p>In order for inlining to behave correctly, landing pads must be prepared to
handle selector results that they did not originally advertise. Suppose that a
function catches exceptions of type <tt class="docutils literal"><span class="pre">A</span></tt>, and it&#8217;s inlined into a function that
catches exceptions of type <tt class="docutils literal"><span class="pre">B</span></tt>. The inliner will update the <tt class="docutils literal"><span class="pre">landingpad</span></tt>
instruction for the inlined landing pad to include the fact that <tt class="docutils literal"><span class="pre">B</span></tt> is also
caught. If that landing pad assumes that it will only be entered to catch an
<tt class="docutils literal"><span class="pre">A</span></tt>, it&#8217;s in for a rude awakening.  Consequently, landing pads must test for
the selector results they understand and then resume exception propagation with
the <a class="reference external" href="LangRef.html#i_resume">resume instruction</a> if none of the conditions
match.</p>
</div>
</div>
<div class="section" id="exception-handling-intrinsics">
<h2><a class="toc-backref" href="#id17">Exception Handling Intrinsics</a><a class="headerlink" href="#exception-handling-intrinsics" title="Permalink to this headline">¶</a></h2>
<p>In addition to the <tt class="docutils literal"><span class="pre">landingpad</span></tt> and <tt class="docutils literal"><span class="pre">resume</span></tt> instructions, LLVM uses several
intrinsic functions (name prefixed with <tt class="docutils literal"><span class="pre">llvm.eh</span></tt>) to provide exception
handling information at various points in generated code.</p>
<div class="section" id="llvm-eh-typeid-for">
<span id="id4"></span><h3><a class="toc-backref" href="#id18">llvm.eh.typeid.for</a><a class="headerlink" href="#llvm-eh-typeid-for" title="Permalink to this headline">¶</a></h3>
<div class="highlight-llvm"><div class="highlight"><pre><span class="k">i32</span> <span class="vg">@llvm.eh.typeid.for</span><span class="p">(</span><span class="k">i8</span><span class="p">*</span> <span class="nv">%type_info</span><span class="p">)</span>
</pre></div>
</div>
<p>This intrinsic returns the type info index in the exception table of the current
function.  This value can be used to compare against the result of
<tt class="docutils literal"><span class="pre">landingpad</span></tt> instruction.  The single argument is a reference to a type info.</p>
</div>
<div class="section" id="llvm-eh-sjlj-setjmp">
<span id="id5"></span><h3><a class="toc-backref" href="#id19">llvm.eh.sjlj.setjmp</a><a class="headerlink" href="#llvm-eh-sjlj-setjmp" title="Permalink to this headline">¶</a></h3>
<div class="highlight-llvm"><div class="highlight"><pre><span class="k">i32</span> <span class="vg">@llvm.eh.sjlj.setjmp</span><span class="p">(</span><span class="k">i8</span><span class="p">*</span> <span class="nv">%setjmp_buf</span><span class="p">)</span>
</pre></div>
</div>
<p>For SJLJ based exception handling, this intrinsic forces register saving for the
current function and stores the address of the following instruction for use as
a destination address by <a class="reference internal" href="#llvm-eh-sjlj-longjmp">llvm.eh.sjlj.longjmp</a>. The buffer format and the
overall functioning of this intrinsic is compatible with the GCC
<tt class="docutils literal"><span class="pre">__builtin_setjmp</span></tt> implementation allowing code built with the clang and GCC
to interoperate.</p>
<p>The single parameter is a pointer to a five word buffer in which the calling
context is saved. The front end places the frame pointer in the first word, and
the target implementation of this intrinsic should place the destination address
for a <a class="reference internal" href="#llvm-eh-sjlj-longjmp">llvm.eh.sjlj.longjmp</a> in the second word. The following three words are
available for use in a target-specific manner.</p>
</div>
<div class="section" id="llvm-eh-sjlj-longjmp">
<span id="id6"></span><h3><a class="toc-backref" href="#id20">llvm.eh.sjlj.longjmp</a><a class="headerlink" href="#llvm-eh-sjlj-longjmp" title="Permalink to this headline">¶</a></h3>
<div class="highlight-llvm"><div class="highlight"><pre><span class="kt">void</span> <span class="vg">@llvm.eh.sjlj.longjmp</span><span class="p">(</span><span class="k">i8</span><span class="p">*</span> <span class="nv">%setjmp_buf</span><span class="p">)</span>
</pre></div>
</div>
<p>For SJLJ based exception handling, the <tt class="docutils literal"><span class="pre">llvm.eh.sjlj.longjmp</span></tt> intrinsic is
used to implement <tt class="docutils literal"><span class="pre">__builtin_longjmp()</span></tt>. The single parameter is a pointer to
a buffer populated by <a class="reference internal" href="#llvm-eh-sjlj-setjmp">llvm.eh.sjlj.setjmp</a>. The frame pointer and stack
pointer are restored from the buffer, then control is transferred to the
destination address.</p>
</div>
<div class="section" id="llvm-eh-sjlj-lsda">
<h3><a class="toc-backref" href="#id21">llvm.eh.sjlj.lsda</a><a class="headerlink" href="#llvm-eh-sjlj-lsda" title="Permalink to this headline">¶</a></h3>
<div class="highlight-llvm"><div class="highlight"><pre><span class="k">i8</span><span class="p">*</span> <span class="vg">@llvm.eh.sjlj.lsda</span><span class="p">()</span>
</pre></div>
</div>
<p>For SJLJ based exception handling, the <tt class="docutils literal"><span class="pre">llvm.eh.sjlj.lsda</span></tt> intrinsic returns
the address of the Language Specific Data Area (LSDA) for the current
function. The SJLJ front-end code stores this address in the exception handling
function context for use by the runtime.</p>
</div>
<div class="section" id="llvm-eh-sjlj-callsite">
<h3><a class="toc-backref" href="#id22">llvm.eh.sjlj.callsite</a><a class="headerlink" href="#llvm-eh-sjlj-callsite" title="Permalink to this headline">¶</a></h3>
<div class="highlight-llvm"><div class="highlight"><pre><span class="kt">void</span> <span class="vg">@llvm.eh.sjlj.callsite</span><span class="p">(</span><span class="k">i32</span> <span class="nv">%call_site_num</span><span class="p">)</span>
</pre></div>
</div>
<p>For SJLJ based exception handling, the <tt class="docutils literal"><span class="pre">llvm.eh.sjlj.callsite</span></tt> intrinsic
identifies the callsite value associated with the following <tt class="docutils literal"><span class="pre">invoke</span></tt>
instruction. This is used to ensure that landing pad entries in the LSDA are
generated in matching order.</p>
</div>
</div>
<div class="section" id="asm-table-formats">
<h2><a class="toc-backref" href="#id23">Asm Table Formats</a><a class="headerlink" href="#asm-table-formats" title="Permalink to this headline">¶</a></h2>
<p>There are two tables that are used by the exception handling runtime to
determine which actions should be taken when an exception is thrown.</p>
<div class="section" id="exception-handling-frame">
<h3><a class="toc-backref" href="#id24">Exception Handling Frame</a><a class="headerlink" href="#exception-handling-frame" title="Permalink to this headline">¶</a></h3>
<p>An exception handling frame <tt class="docutils literal"><span class="pre">eh_frame</span></tt> is very similar to the unwind frame
used by DWARF debug info. The frame contains all the information necessary to
tear down the current frame and restore the state of the prior frame. There is
an exception handling frame for each function in a compile unit, plus a common
exception handling frame that defines information common to all functions in the
unit.</p>
</div>
<div class="section" id="exception-tables">
<h3><a class="toc-backref" href="#id25">Exception Tables</a><a class="headerlink" href="#exception-tables" title="Permalink to this headline">¶</a></h3>
<p>An exception table contains information about what actions to take when an
exception is thrown in a particular part of a function&#8217;s code. There is one
exception table per function, except leaf functions and functions that have
calls only to non-throwing functions. They do not need an exception table.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="LinkTimeOptimization.html" title="LLVM Link Time Optimization: Design and Implementation"
             >next</a> |</li>
        <li class="right" >
          <a href="CodeGenerator.html" title="The LLVM Target-Independent Code Generator"
             >previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>

          <li><a href="subsystems.html" >Subsystem Documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, LLVM Project.
      Last updated on 2012-12-21.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>